package com.atguigu.gulimall.order.controller;

import com.atguigu.gulimall.order.entity.OrderEntity;
import com.atguigu.gulimall.order.entity.OrderItemEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RabbitmqController {


    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/sendmq")
    public void send(@RequestParam(value = "num",defaultValue = "5") int num) {

        for (int i = 0; i < num; i++) {
            if (true){
                OrderItemEntity orderItemEntity = new OrderItemEntity();

                orderItemEntity.setId(1L + i );
                orderItemEntity.setSpuName("huawei");
                orderItemEntity.setCategoryId(11L);
                rabbitTemplate.convertAndSend("exchange.direct1","atguigu.hello",orderItemEntity);
            }else {
                OrderEntity orderEntity = new OrderEntity();
                orderEntity.setId(1L + i);
                orderEntity.setBillContent("oppo");
                rabbitTemplate.convertAndSend("exchange.direct1","atguigu22.hello22",orderEntity);

            }
        }


    }
}
